<?php
   class Model_hotelroomprice extends CI_Model{
		protected $_table = "tbl_hotelroomprice";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		public function listall($limit,$start){
			return $this->db->get($this->_table)->result_array();
		}
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		public function getpricebyroomid($id){
			$this->db->where("roomid",$id);	
			$this->db->order_by("id","DESC");
			return $this->db->get($this->_table)->result_array();
		}
		public function getbyroomidanddatetime($idroom,$datetime){
			$r=array();
			$this->db->where("roomid",$idroom);
			$this->db->where("fromdate <=",$datetime);
			$this->db->where("todate >=",$datetime);
			$data=$this->db->get($this->_table)->result_array();
			if(count($data)>0){
				return $data[0];
			}
			return $r;
		}
		public function getallbyroomid($roomid){
			$query=$this->db->query("select * from tbl_hotelroomprice where roomid=".$roomid);
			return $query->result_array();
		}
		public function getminpricebyhotelidanddate($hotelid,$date){
			$query=$this->db->query("select * from tbl_hotelroomprice where roomid in (select id from tbl_hotelroom where hotelid=$hotelid) and fromdate <='$date' and todate>='$date' order by price");
			return $query->row_array();
		}
	}